import { Constructor } from "cc";
import { IEntityFilter, ComponentFilter, TagFilter, ExcludeTagFilter, CompositeFilter, EnableFilter } from "./EntityFilter";
import { ECSCmp } from "./ECSComp";
import { ECSEntity } from "./ECSEntity";

/**
 * 过滤器构建器 - 提供流畅的API来构建复杂过滤器
 */
export class FilterBuilder {
    private _filters: IEntityFilter[] = [];

    /** 要求包含指定组件 */
    withComps(...comps: Constructor<ECSCmp>[]): FilterBuilder {
        if (comps.length > 0) {
            this._filters.push(new ComponentFilter(comps));
        }
        return this;
    }

    /** 要求包含指定组件 */
    withEnable(): FilterBuilder {
        this._filters.push(new EnableFilter());
        return this
    }

    /** 要求包含指定标签 */
    withTags(...tags: string[]): FilterBuilder {
        if (tags.length > 0) {
            this._filters.push(new TagFilter(tags));
        }
        return this;
    }

    /** 要求不包含指定标签 */
    exludeTags(...tags: string[]): FilterBuilder {
        if (tags.length > 0) {
            this._filters.push(new ExcludeTagFilter(tags));
        }
        return this;
    }

    /** 构建最终的过滤器 */
    build(): IEntityFilter {
        return new CompositeFilter(this._filters, 'AND');
    }

    /** 构建OR逻辑的过滤器 */
    buildOr(): IEntityFilter {
        return new CompositeFilter(this._filters, 'OR');
    }

    /** 重置构建器 */
    reset(): FilterBuilder {
        this._filters = [];
        return this;
    }

    static create() {
        return new FilterBuilder();
    }
}